# 作者：SP
# 开发时间：2025/3/30 14:44
import sys
from PyQt5.QtWidgets import QDialog,QApplication
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import *

class myDialog(QDialog):
    def __init__(self):
        super().__init__()
    #重新实现按键处理函数keyPressEvent
    def keyPressEvent(self, event):
        if event.key() != Qt.Key_Escape:
            '''判断按下的键是不是Esc键'''
            QDialog.keyPressEvent(self,event)
        else:   #否则显示一个信息框
            QMessageBox.information(self,'Notice','No close!',QMessageBox.Yes)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    mywindow = myDialog()
    mywindow.exec_()
    sys.exit(app.exec_())